// 处理请求事件
const sendHandle = () => {
    const send = (ctx) => {
        // 成功请求
        return (data, message = '请求成功', code = 200) => {
            ctx.set("Content-Type", "application/json;charset=utf-8");
            ctx.body = {
                code,
                data,
                message
            }
        }
    }
    const sendErr = (ctx) => {
        // 请求失败
        return (code, message = '请求失败') => {
            ctx.set("Content-Type", "application/json;charset=utf-8");
            ctx.status = code
            ctx.body = {
                code,
                message
            }
        }
    }
    return async (ctx, next) => {
        ctx.send = send(ctx)
        ctx.sendErr = sendErr(ctx)
        await next();
    }
}

module.exports =  sendHandle